package meterMonitor.util;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.InetSocketAddress;
import java.net.Socket;

public class TcpClient {

    public static void main(String[] args) throws IOException {
        Socket client = new Socket();
        try {
            client.connect(new InetSocketAddress("192.168.1.145", 8899), 5000);
            OutputStream os = client.getOutputStream();
            byte[] last = new byte[]{0x00, 0x03, 0x02, 0x00, 0x00, 0x08, 0x44, 0x65};
            os.write(last);
            os.flush();
            // try {
            //     Thread.sleep(300);
            // } catch (InterruptedException e) {
            //     // TODO Auto-generated catch block
            //     e.printStackTrace();
            // }
            InputStream is2 = client.getInputStream();
            byte[] b = new byte[1024];
            int read = is2.read(b);
            // String res = bytetohex.bytesToHex(b);

            for (int i = 0; i < read; i++) {
                System.out.print(Integer.toHexString(b[i]) + " ");
            }


            // System.out.println(res);
            os.close();
            is2.close();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        client.close();
    }
}
